import { GridApi } from 'ag-grid-community';
import { useEmitter } from 'src/emitter';
import { Ref } from 'vue';

/**
 * 表格组件筛选 composable
 */
export const useFilter = <TData = any>(gridApi: Ref<GridApi<TData> | undefined>, options: { id?: string } = {}) => {
  useEmitter('table_filter', payload => {
    if (payload.id === options.id) {
      gridApi.value?.setQuickFilter(payload.query);
    }
  });
};
